#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

#define NOISY_TEST 1

void checkEndTurn_cycle(struct gameState *pre) {
  struct gameState post;
  int i;
  int player;
  int cycle = 1;
  memcpy (&post, pre, sizeof(struct gameState));
  endTurn(&post);
  for(i=1; i<(post.numPlayers*3); i++) {
      player = i % (post.numPlayers);
      if (cycle == 3) {
          cycle = 1;
      }
      if (player != 0) {
          assert(post.discardCount[player-1] == 5*cycle);
      } else {
          assert(post.discardCount[post.numPlayers-1] == 5*cycle);
          cycle++;
      }
      assert(post.whoseTurn == player);
      assert(post.handCount[player] == 5);
      assert(post.coins != 0);
      assert(post.numActions == 1);
      assert(post.numBuys == 1);
      assert(post.playedCardCount == 0);
      endTurn(&post);
  }
}

int run_tests7() {
  int k[10] = {adventurer, council_room, feast, gardens, mine,
	       remodel, smithy, village, baron, great_hall};
  struct gameState G;
  printf ("FIXED TESTING endTurn.\n");
  initializeGame(2, k, 1, &G);
  printf ("Testing endTurn: 2 players.\n");
  checkEndTurn_cycle(&G);
  initializeGame(3, k, 1, &G);
  printf ("Testing endTurn: 3 players.\n");
  checkEndTurn_cycle(&G);
  initializeGame(4, k, 1, &G);
  printf ("Testing endTurn: 4 players.\n");
  checkEndTurn_cycle(&G);
  printf ("ALL TESTS OK\n");
  return 0;
}
